﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Web.Information
{
    public partial class article : System.Web.UI.Page
    {
        public Entity.Informations infoObj = new Entity.Informations();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["id"] == null)
            {
                Response.Write("~/index.aspx");
            }
            else
            {
                Bind();
            }
        }

        private void Bind()
        {
            //咨询
            DataSet infoDs = (new Controller.InformationShow()).GetArticleTop5(5, Web.AppCode.Sys_Config.GetCurrentCityCode(),"5");
            rptInfoTop5.DataSource = infoDs.Tables[0].DefaultView;
            rptInfoTop5.DataBind();

            infoObj = (new Controller.InformationShow()).SelectSingle(Request["id"].ToString());


            //d
            DataSet corpds = (new Controller.CorpInfoShow()).GetArticleDiffType(Web.AppCode.Sys_Config.GetCurrentCityCode());
            DataView dvCorp = corpds.Tables[0].DefaultView;
            rptCorpTop3.DataSource = GetTopDataViewRows(dvCorp, 3);
             rptCorpTop3.DataBind();
        }

        private DataView GetTopDataViewRows(DataView dv, int n)
        {
            DataTable dt = dv.Table.Clone();

            for (int i = 0; i <= n - 1; i++)
            {
                if (i >= dv.Count)
                {
                    break;
                }
                dt.ImportRow(dv[i].Row);
            }

            return new DataView(dt, dv.RowFilter, dv.Sort, dv.RowStateFilter);
        }
    }
}
